//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost:8080/'
// axios.defaults.baseURL='http://api.pethome.java.itsource.cn/'
//全局属性配置，在任意组件内可以使用this.$http获取axios对象
Vue.prototype.$http = axios


//axios前置拦截器携带localStorage里面的token到后台
//============axios前置拦截器携带token到后端====================//
axios.interceptors.request.use(
    config=>{
        //判断localStoarge中有token需要携带到后台
        let token =  localStorage.getItem("token");
        if(token){
            config.headers['token'] = token;
        }
        return config;//拦截做的事情ok，也要返回继续往下走
    },
    error=>{
        Promise.reject(error);
    })
//============axios前置拦截器携带token到后端====================//
//============axios后置拦截器携带token到后端====================//
axios.interceptors.response.use(
    config=>{
        //判断登录错误跳转登录页面
        console.log(config);
        console.log(config.data);
        let result = config.data;
        if(!result.success&&result.message=='noLogin')
        {
            localStorage.removeItem("token");
            localStorage.removeItem("user");
            location.href="login.html";
        }
        return config;//拦截做的事情ok，也要返回继续往下走
    },
    error=>{
        Promise.reject(error);
    })
//============axios后置拦截器携带token到后端====================//


//前端页面拦截
//前端的登录拦截-common.js会被所有的界面导入
// 判断localStorage中是否有logininfo
let url = location.href;
//不是登录且不是注册，就要拦截
// if(url.indexOf("login.html")==-1 && url.indexOf("register.html")==-1&&url.indexOf("index.html")==-1&&url.indexOf("callback.html")==-1&&url.indexOf("binder.html")==-1)
// {
//     let loginInfo = localStorage.getItem("user");
//     if(!loginInfo){
//         location.href = "/login.html"
//     }
// }

function parseUrlParams(url) {
    //code=011JBI0w32eRLW2U6j4w34klDx4JBI07&state=1
    let paramStr = url.substring(url.indexOf("?")+1)
    let paramArray = paramStr.split("&"); //[code=011JBI0w32eRLW2U6j4w34klDx4JBI07,state=1]
    let resultObj = {};
    for(let i=0;i<paramArray.length;i++){
        let tmp = paramArray[i]//code=011JBI0w32eRLW2U6j4w34klDx4JBI07
        let paramName = tmp.split("=")[0]
        let paramValue = tmp.split("=")[1]
        resultObj[paramName] = paramValue;
    }
    return resultObj;
}


const  fastDfsUlr = "http://47.95.117.210:8888";
// const  fastDfsActionUlr = 'http://api.pethome.java.itsource.cn/fastDfs';
const  fastDfsActionUlr = 'http://localhost:8080/fastDfs';
